<template>
	<view class="container">
		<view class="content">
			<rich-text :nodes="$tools.formatRichText(content)"></rich-text>
		</view>

		<view class="levels py-30">
			<view class="level mb-36" v-for="certification in list" :key="certification.id">
				<view class="head"> {{ certification.level }} </view>
				<view class="date mt-20" v-if="certification.date">{{ certification.date }}</view>
				<view class="body mt-50">
					<view class="title">{{ certification.title }}</view>
					<view class="content mt-50">
						<rich-text :nodes="$tools.formatRichText(certification.content)"></rich-text>
					</view>
				</view>
				<view class="footer mt-80">
					<uv-button text="立即购买" color="#292A43" shape="circle"></uv-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getSystemConfig, getCertificationList } from '@/api/index';
export default {
	data() {
		return {
			title: 'Hello',
			content: '',
			query: {
				page: 1,
				limit: 10,
			},
			list: [],
			all: false,
		};
	},
	onShareAppMessage() {},
	onShareTimeline() {},
	onLoad() {
		this.getInit();

		this.query.page = 1;
		this.list = [];
		this.all = false;
		this.getData();
	},
	onShow() {},
	onReachBottom() {
		if (this.all == true) {
			this.$tools.toast('已加载全部数据...');
			return false;
		}
		this.query.page++;
		this.getData();
	},
	onPullDownRefresh() {
		this.query.page = 1;
		this.list = [];
		this.all = false;
		this.getData();
	},
	methods: {
		getInit() {
			//系统配置
			getSystemConfig().then((res) => {
				console.log(res);
				this.content = res.data.certification;
			});
		},
		getData() {
			getCertificationList(this.query).then((res) => {
				console.log(res);
				const list = res.data.data;
				this.list = this.list.concat(list);
				if (this.query.page == res.data.last_page) {
					this.all = true;
				}
				uni.stopPullDownRefresh();
			});
		},
	},
};
</script>

<style lang="scss">
@import 'index.scss';
</style>
